import axios from 'axios'
//axios.defaults.baseURL = 'http://127.0.0.1:3000';
const defHttp = {
  get: (url: string, params?: any, opt?: any) => {
    return defHttp.axios(opt).get(url, { params: params })
  },
  post: (url: string, params?: any, opt?: any) => {
    return defHttp.axios(opt).post(url, params)
  },
  axios:(opt)=>{
    const tarOption = deepMerge({
      timeout: 10000,
      baseURL: 'http://124.70.73.91:3002',
      headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
      }
      },opt||{}
    )
    return  axios.create(tarOption)  
  } 
}

function deepMerge<T = any>(src: any = {}, target: any = {}): T {
    let key: string;
    for (key in target) {
      src[key] = (src[key] && typeof(src[key])=='object') ? deepMerge(src[key], target[key]) : (src[key] = target[key]);
    }
    return src;
}
export  {defHttp}